/*
 * client_session.h
 *
 *  Created on: Aug 1, 2013
 *      Author: killerg
 */

#ifndef CLIENT_SESSION_H_
#define CLIENT_SESSION_H_

#include "share/session_mgr.h"
#include "share/cl_msg.pb.h"

enum ELogonStage {
    ELInvalid     =  0,
    ELConnected =  1,
    ELAuthing     =  2,
    ELAuthed     =  3,
    ELSelecting =  4,
    ELSelected     =  5,
};

const int ELSTAGENUM = ELSelected + 1;

extern const char* LogonStageName[];

struct client_session_t {
    tran_s* _trans;
    int64_t _sessid;
    double _idle_timer;
    client_session_t(int64_t sessid_, tran_s* trans) {
        _trans = trans;
        _sessid = sessid_;
        _idle_timer = 10.0f;

        key = -1;
        playerid = -1;
        stage = ELInvalid;
        idle_timer = 30.0f;
        active_time = 0;
    }
    void update();
    void on_connect();
    void on_disconnect();
    bool send_msg(cl::LMsg* &msg);

    std::string account;
    std::string plat;
    int32_t playerid;
    ELogonStage stage;
    double idle_timer;
    int32_t key;
    std::string mc;
    int32_t active_time;
};

struct clientsess_mgr_t : public svr_session_t<client_session_t, cl::CMsg, cl::CMsgID_ARRAYSIZE, cl::LMsg, cl::LMsgID_ARRAYSIZE> {
    typedef svr_session_t<client_session_t, cl::CMsg, cl::CMsgID_ARRAYSIZE, cl::LMsg, cl::LMsgID_ARRAYSIZE> base;

    bool init();
};



#endif /* CLIENT_SESSION_H_ */
